package com.ecoolex.chinadutyfree.retailer.core.manager;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ecoolex.chinadutyfree.retailer.core.dao.DirectMailGoodsOrderAfterSalesRecordDAO;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderAfterSalesRecord;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderAfterSalesRecord.Column;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderAfterSalesRecordExample;
import com.ecoolex.chinadutyfree.retailer.entity.DirectMailGoodsOrderAfterSalesRecordExample.Criteria;
import com.ecoolex.chinadutyfree.retailer.enums.DirectMailGoodsOrderAfterSalesRecordType;

@Service
public class DirectMailGoodsOrderAfterSalesRecordManager {
	
    @Autowired
    private DirectMailGoodsOrderAfterSalesRecordDAO dao;
    
    public void create(Integer orderId,Integer afterSalesId,DirectMailGoodsOrderAfterSalesRecordType type,String remark,String evidenceImage,String createUser) {
    	DirectMailGoodsOrderAfterSalesRecord record = new DirectMailGoodsOrderAfterSalesRecord();
    	record.setOrderId(orderId);
    	record.setAfterSalesId(afterSalesId);
    	record.setContentType(type.real());
    	record.setRemark(remark);
    	record.setEvidenceImage(evidenceImage);
    	record.setDeleted(DirectMailGoodsOrderAfterSalesRecord.NOT_DELETED);
    	record.setCreateUser(createUser);
    	record.setCreateTime(Date.from(Instant.now()));
    	record.setUpdateUser(createUser);
    	record.setUpdateTime(Date.from(Instant.now()));
    	dao.insert(record);
    }
    
    public List<DirectMailGoodsOrderAfterSalesRecord> listByAfterSalesId(Integer afterSalesId){
    	DirectMailGoodsOrderAfterSalesRecordExample example = new DirectMailGoodsOrderAfterSalesRecordExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andAfterSalesIdEqualTo(afterSalesId).andDeletedEqualTo(DirectMailGoodsOrderAfterSalesRecord.NOT_DELETED);
    	example.orderBy(Column.createTime.desc());
    	return dao.selectByExample(example);
    }
    
    public List<DirectMailGoodsOrderAfterSalesRecord> listByOrderId(Integer orderId){
    	DirectMailGoodsOrderAfterSalesRecordExample example = new DirectMailGoodsOrderAfterSalesRecordExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andOrderIdEqualTo(orderId).andDeletedEqualTo(DirectMailGoodsOrderAfterSalesRecord.NOT_DELETED);
    	example.orderBy(Column.createTime.desc());
    	return dao.selectByExample(example);
    }
}